/**
 *    Copyright (C) 2008, 2009  Victor Smirnov <aist11@gmail.com>
 *
 *    This program is free software; you can redistribute it and/or modify
 *    it under the terms of the GNU General Public License as published by
 *    the Free Software Foundation; either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU General Public License for more details.
 *
 *    You should have received a copy of the GNU General Public License along
 *    with this program; if not, write to the Free Software Foundation, Inc.,
 *    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 *    See LICENSE.exceptions in the root folder of this project for possible
 *    exceptions
 *
 */

#ifndef _CUBEFS_CORE_TOOLS_TYPES_TRAITS_H
#define _CUBEFS_CORE_TOOLS_TYPES_TRAITS_H


#include <iostream>
#include <typeinfo>

namespace cubefs        {
namespace tools         {




template <typename T>
struct ValueTraits {
    static const Long Size = sizeof(T); //T::SIZE;
    typedef T Type;
    static const bool IsPrimitive = false;
};


#define CUBEFS_VALUE_TRAITS(ValueType, MinValue, MaxValue)                      \
template <>                                                                     \
struct ValueTraits<ValueType> {                                                 \
    static const Long Size              = sizeof(ValueType);                    \
    typedef ValueType                   Type;                                   \
                                                                                \
    static const ValueType Min = MinValue;                                      \
    static const ValueType Max = MaxValue;                                      \
    static const bool IsPrimitive = true;                                       \
};                                                                              \
                                                                                \
template <>                                                                     \
struct ValueTraits<const ValueType> {                                           \
    static const Long Size              = sizeof(ValueType);                    \
    typedef const ValueType                   Type;                             \
                                                                                \
    static const ValueType Min = MinValue;                                      \
    static const ValueType Max = MaxValue;                                      \
    static const bool IsPrimitive = true;                                       \
}


const Long LongMin = 1l << (sizeof(Long) * 8 - 1);
const Long LongMax = ~LongMin;

//const ULong ULongMin = 0l;
//const ULong ULongMax = ~ULongMin;

CUBEFS_VALUE_TRAITS(Byte, 0x80, 0x7f);
CUBEFS_VALUE_TRAITS(Short,0x8000, 0x7fff);
CUBEFS_VALUE_TRAITS(Int,  0x80000000, 0x7fffffff);
CUBEFS_VALUE_TRAITS(Long, LongMin, LongMax);
CUBEFS_VALUE_TRAITS(BigInt, 0x8000000000000000ll, 0x7fffffffffffffffll);

CUBEFS_VALUE_TRAITS(UByte,  0, 0xFF);
CUBEFS_VALUE_TRAITS(UShort, 0, 0xFFFF);
CUBEFS_VALUE_TRAITS(UInt,   0, 0xFFFFFFFF);
//CUBEFS_VALUE_TRAITS(ULong,  ULongMin, ULongMax);
//CUBEFS_VALUE_TRAITS(UBigInt,0ull, 0xFFFFFFFFFFFFFFFFull);




#undef CUBEFS_VALUE_TRAITS

} //tools
} //cubefs

#endif //_CUBEFS_CORE_TOOLS_TYPES_TRAITS_H
